home *** CD-ROM | disk | FTP | other *** search
- Path: mundook.cs.mu.OZ.AU!fjh
- From: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
- Newsgroups: comp.lang.ada,comp.lang.c++
- Subject: Re: Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user)
- Date: 31 Mar 1996 18:36:19 GMT
- Organization: Comp Sci, University of Melbourne
- Message-ID: <4jmjb3$rbv@mulga.cs.mu.OZ.AU>
- References: <wnewmanDoxrCp.DKv@netcom.com> <Dp1oAw.7Cz@world.std.com> <EACHUS.96Mar29191146@spectre.mitre.org> <4jlmn5$h1k@Nntp1.mcs.net>
- NNTP-Posting-Host: mundook.cs.mu.oz.au
-
- mikey@mcs.com (Mike Young) writes:
-
- >eachus@spectre.mitre.org> says...
- >>The choice was between Ada and a shell script...I chose Ada:
- >>
- >>generic
- >> with procedure To_Do(File: in String);
- >>procedure Iterate_Files(Pattern: in String := "*";
- >> Directory: in String := "");
- >>-- This generic iterates over all files in a directory matching Pattern and
- >>-- calls To_Do once for each such directory entry. If a file has several
- >>-- links in the directory To_Do will be called once for each.
- >
- >=========
- >I don't know about that, Robert. The equivalent shell script would be:
- >
- >#---- iterateFiles
- >fileop=$1;shift
- >for file in $*; do $fileop $file; done
-
- No, that shell script, like the vast majority of shell scripts around,
- is buggy. Writing correct, portable shell scripts is actually pretty tricky.
-
- Here's a better version:
-
- fileop="$1"; shift
- case $# in
- 0) ;;
- *) for file in "$@"; do $fileop "$file"; done ;;
- esac
-
- Now just be careful with the quoting when you invoke it...
-
- > You are not restricted to procedures in that same program, all system
- > utilities are directly available, you don't need to rebuild to add new
- > features, and you need not have bothered with your 50 lines of code.
- > All are big wins, IMO.
-
- Oh, certainly shell scripts are extremely useful.
- But it helps to be aware of their drawbacks as well as their advantages.
-
- --
- Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
- WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
- PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
-